<template>
  <div class="box">
    <div class="head-fixed">
      <div class="head">
        <div class="head-div">
          <img src="../../assets/zjt2.png" alt="" class="back" @click="back()"/>
        </div>
        <div class="head-search">求职意向</div>
      </div>
    </div>
    <div class="content">
      <div class="block" v-for="item in jobList">
        <div class="block-top">
          <span>{{ item.positionName }}</span>
          <span style="position: relative; z-index: 50">{{ item.expectedSalaryName }}</span>
        </div>
        <div class="block-class">
          <span>{{ item.cityName }}</span>
          <span>{{ item.jobStatusName }}</span>
        </div>
        <div class="block-button">
          <div class="blue" @click="update(item.id)">修改</div>
          <div class="gray" @click="deleteItem(item.id)">删除</div>
        </div>
      </div>
      <div v-if="jobList.length < 3" class="blocks-btn" @click="go('/addJob')">添加求职信息</div>
    </div>

  </div>
</template>

<script>
export default {
  inject: ['reload'],
  name: 'job',
  components: {},
  created () {
    // created 在模板渲染成html前调用，即通常初始化某些属性值，然后再渲染成视图
    this.init()
  },
  mounted () {
    // mounted在模板渲染成html后调用，通常是初始化页面完成后，再对html的dom节点进行一些需要的操作
  },
  // data() 为变量赋值等
  data () {
    return {
      // status为用户身份，0是求职者，1是招聘者
      status: localStorage.status,
      jobList: []
    }
  },
  // methods 编写js函数
  methods: {
    deleteItem (id) {
      this.$http({
        method: 'get',
        params: {},
        url: 'api/userIntentionJob/deleteById/' + id
      }).then(({data}) => {
        if (data && data.code == 0) {
          this.init()
        }
      })
    },
    update (id) {
      this.$router.push({path: '/addJob', query: {id: id}})
    },
    init () {
      this.$http({
        method: 'get',
        params: {},
        url: 'api/userIntentionJob/getJobList/' + window.localStorage.getItem('userId')
      }).then(({data}) => {
        this.jobList = data.ycUserIntentionJobList
      })
    },
    back () {
      this.$router.push({name: 'usersResume'})
    },
    go (r) {
      this.$router.push(r)
    }
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
html,
body,
.tac,
.box,
.tab-left,
.tab-left .el-menu {
  height: 100%;
}

.box {
  width: 100%;
  background: rgb(248, 248, 248);
}

.head-fixed {
  width: 100%;
  height: 43px;
  position: fixed;
  z-index: 999;
}

.head {
  background: #3e63a8;
  color: #fff;
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.back {
  width: 14px;
  height: 14px;
}

.head div img {
  width: 20px;
  height: 20px;
}

.head-search {
  box-sizing: border-box;
  flex: 1;
  text-align: center;
  font-size: 14px;
}

.content {
  position: relative;
  top: 43px;
  width: 100%;
  box-sizing: border-box;
  padding: 20px;
}

.block {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 20px 10px 10px;
  background: #fff;
  margin-bottom: 10px;
  display: flex;
  flex-flow: column;
  justify-content: space-between;
  border-radius: 10px;
  box-shadow: 2px 2px 5px #c7c7c7;
  position: relative;
}

.block .block-top {
  font-size: 14px;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
}

.block-top span:first-child {
  color: #333;
  font-weight: 700;
}

.block-top span:last-child {
  color: #3e63a8;
}

.block-calss {
  width: 100%;
}

.block-class span {
  color: #757575;
  font-size: 10px;
  padding: 2px 0px;
  border-radius: 3px;
  margin-right: 10px;
}

.block-button {
  width: 100%;
  display: flex;
  margin-top: 10px;
}

.block-button div {
  color: #fff;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 5px;
  margin-right: 5px;
}

.blue {
  background: #3e63a8;
}

.gray {
  background: #c7c7c7;
}

.blocks-btn {
  width: 100%;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  background: #3e63a8;
  border-radius: 5px;
  font-size: 14px;
  margin-top: 50px;
}
</style>
